
package com.epam.android.training.level1.rss;

import android.util.Log;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author Anton Novikau
 */
public class LightFeedBo implements NewsFeed {

  private static final String TAG = "FeedBo";

  private long id;

  private String title;

  private URL feedUrl;

  private URL link;

  private URL iconUrl;

  private List<String> categories;

  @Override
  public boolean isLight() {
    return true;
  }

  @Override
  public long getId() {
    return id;
  }

  @Override
  public void setId(long id) {
    this.id = id;
  }

  @Override
  public String getTitle() {
    return title;
  }

  @Override
  public void setTitle(String title) {
    this.title = title;
  }

  @Override
  public URL getFeedUrl() {
    return feedUrl;
  }

  @Override
  public void setFeedUrl(URL feedUrl) {
    this.feedUrl = feedUrl;
  }

  @Override
  public void setFeedUrl(String feedUrl) {
    try {
      this.feedUrl = new URL(feedUrl);
    } catch (MalformedURLException e) {
      Log.e(TAG, "Unable to parse URL", e);
    }
  }

  @Override
  public URL getLink() {
    return link;
  }

  @Override
  public void setLink(URL link) {
    this.link = link;
  }

  @Override
  public void setLink(String link) {
    try {
      this.link = new URL(link);
    } catch (MalformedURLException e) {
      Log.e(TAG, "Unable to parse feed link", e);
    }
  }

  @Override
  public URL getIconUrl() {
    return iconUrl;
  }

  @Override
  public void setIconUrl(URL iconUrl) {
    this.iconUrl = iconUrl;
  }

  @Override
  public void setIconUrl(String iconUrl) {
    try {
      this.iconUrl = new URL(iconUrl);
    } catch (MalformedURLException e) {
      Log.e(TAG, "Unable to parse icon link", e);
    }
  }

  @Override
  public List<String> getCategories() {
    if (categories == null) {
      categories = new ArrayList<String>();
    }

    return categories;
  }

  @Override
  public void addCategory(String category) {
    getCategories().add(category);
  }

  @Override
  public void addCategories(Collection<String> categories) {
    getCategories().addAll(categories);
  }

  @Override
  public void setCategories(List<String> categories) {
    this.categories = categories;
  }

  @Override
  public List<ItemBo> getItems() {
    throw new UnsupportedOperationException("Light feed holder does not support items.");
  }

  @Override
  public void addItem(ItemBo item) {
    throw new UnsupportedOperationException("Light feed holder does not support items.");
  }

  @Override
  public void addItems(Collection<ItemBo> items) {
    throw new UnsupportedOperationException("Light feed holder does not support items.");
  }

  @Override
  public void setItems(List<ItemBo> items) {
    throw new UnsupportedOperationException("Light feed holder does not support items.");
  }
}
